const { DataTypes, Model } = require('sequelize');
const sequelize = require('../config/database');
const Category = require('./category');
class Tags extends Model { }
Tags.init({
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    allowNull: false,
    autoIncrement: true,
    comment: '记录ID'
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '分类名称'
  },
  category_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '所属分类ID'
  },
  del: {
    comment: '是否删除',
    type: DataTypes.TINYINT,
    allowNull: false,
    values: [0, 1],
    defaultValue: 0 // 默认值为 0（未删除）
  },
  stats: {
    comment: '启禁状态',
    type: DataTypes.INTEGER,
    allowNull: false,
    validate: {
      isIn: [[0, 1, 2]] // 限制值为 0: 待启用、1:已启用 2:已禁止
    },
    defaultValue: 1 // 默认值为 0（未删除）
  },
  ctime: {
    comment: "创建时间",
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: () => new Date().getTime()
  },
  mtime: {
    comment: "更新时间",
    type: DataTypes.BIGINT,
    allowNull: false,
    defaultValue: () => new Date().getTime()
  },
  rmk: {
    comment: '备注信息',
    type: DataTypes.STRING,
    allowNull: true
  }
}, {
  sequelize,
  modelName: 'Tags'
})
Tags.belongsTo(Category, { foreignKey: 'category_id', as: 'category' });
module.exports = Tags;
